package com.itlong.cloud.utils.export;

import org.apache.commons.lang.StringUtils;

import java.lang.reflect.Method;

/**
 * <desc>
 *      值工具类
 * </desc>
 *
 * @createDate 2019/12/26
 */
public class ValueUtil {

    /**
     * <desc>
     *      根据字段名字获取值
     * </desc>
     *
     * @return 值
     * @author wangzhi
     * @createDate 2019/12/26
     */
    public static Object getValueByName(Object obj, Class<?> clazz, String name){
        try {
            if (StringUtils.isBlank(name) || clazz == null) {
                return null;
            }
            //获取get属性方法名
            String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
            Method method = clazz.getMethod(methodName);
            return method.invoke(obj);
        } catch (Exception e) {
            return null;
        }
    }

}
